<template>
  <div id="app">
    <div>
      <p>vuex仓储数据修改</p>
    </div>
    <div>
      <!-- 绑定仓库中的count数据 -->
      <input type="number" placeholder="请输入数字" :value="count" @input="HandleInput">
      <br>
      <button @click="addNumber(5)">添加+5</button>
      <button @click="addNumber(10)">添加+10</button>
      <p>当前数字：{{ count }}</p>
    </div>
    <SubMation></SubMation>
  </div>
</template>
<script>
//导入仓库映射函数
import { mapState } from 'vuex'
import SubMation from './components/SubMation.vue';
export default {
  components: {
    SubMation
  },

  methods: {
    addNumber(num) {
      // 通过仓库的commit方法修改count数据
      this.$store.commit('addNumber', num)
    },
    HandleInput(event) {
      this.$store.commit('addNumber', event.target.value)

    }
  },

  // 通过计算属性映射state中的count数据
  computed: {
    // 映射state中的count数据
    ...mapState(['count', 'user']),
    ...mapState('user', ['age'])
  }

}

</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
